import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:gobelieve/common/utils/global.dart';

/// 用户管理相关
class ReqUser {
  final Dio _dio;

  ReqUser(this._dio);

  /// 注册 可用作登录
  Future<Response> register({
    /// 验证码
    @required String appId,

    /// 邮箱
    @required int uid,

    /// 密码
    @required String username,

    /// true / false 是否在注册后自动完成登录【对于之前已注册的用户，自动完成登录】
    // bool autoLogin = true,
    /// 城市
    String city,

    /// 昵称
    String nick,

    /// 省份
    String province,
  }) {
    if (nick == null) {
      nick = uid.toString();
    }
    return _dio.post('/v1/register', data: {
      "app_id": appId,
      "uid": uid,
      // "pwd": pwd,
      "username": username,
      "nick": nick,
      // "province": province,
    });
  }

  /// http鉴权获取token
  Future<Response> authToken(int uid) {
    return _dio.post('/v1/auth/token', data: {"app_id": G.APP_ID, "uid": uid});
  }
}
